package com.ceshiren.chnjx.wework.page.contact.member;

import com.ceshiren.chnjx.wework.page.BasePage;
import com.ceshiren.chnjx.wework.page.contact.ContactPage;
import com.ceshiren.chnjx.wework.utils.CustomStrUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

/**
 * @author: JJJJ
 * @date:2021/11/3 15:10
 * @Description: TODO
 */
public class AddOrEditMemberPage extends BasePage {
    public AddOrEditMemberPage(WebDriver driver) {
        super(driver);
    }

    private By usernameInput = new By.ByName("username");
    private By nickNameInput = new By.ByName("english_name");
    private By accountInput = new By.ByName("acctid");
    private By phoneInput = new By.ByName("mobile");
    // 男
    private By selectMan = new By.ByCssSelector("input[value='1']");
    // 女
    private By selectLady = new By.ByCssSelector("input[value='2']");
    private By saveBtn = new By.ByLinkText("保存");


    /**
     * 添加成员
     */
    public ContactPage addMember(String account, String name, String nickName, String sex, String phone) {
        sendData(usernameInput,name);
        sendData(nickNameInput,nickName);
        sendData(accountInput,account);
        sendData(phoneInput,phone);
        if (sex.equals("男"))
            clickElement(selectMan);
        else
            clickElement(selectLady);
        clickElement(saveBtn);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return new ContactPage(driver);
    }

    /**
     * 编辑成员
     */
    public MemberDetailPage editMember(String name, String nickName, String phone) {
        if (!CustomStrUtils.isEmpty(name))
            sendData(usernameInput,name);
        if (!CustomStrUtils.isEmpty(nickName))
            sendData(nickNameInput,nickName);
        if (!CustomStrUtils.isEmpty(phone))
            sendData(phoneInput,phone);
        clickElement(saveBtn);
        return new MemberDetailPage(driver);
    }
}
